﻿using System;
using System.Web.UI;
using Business;

namespace ServicesDirectory
{
    public partial class ForgotPassword : System.Web.UI.Page
    {
        protected void PageLoad(object sender, EventArgs e)
        {

        }

        protected void BtnSubmitClick(object sender, ImageClickEventArgs e)
        {
            lblStatus.Text = "";
            CaptchaControl1.ValidateCaptcha(TxtCaptcha.Text);
            if (CaptchaControl1.UserValidated)
            {
                var userBusiness = new UserBusiness();
                var account = TxtUserName.Text;
                var email = TxtEmail.Text;
                var checkEmail = userBusiness.ValidateEmail(account, email);
                if (checkEmail)
                {
                    string message = "";
                    var result = userBusiness.ForgotPassword(account, email, out message);
                    //lblStatus.Text = result;
                    if (result)
                    {
                        TxtCaptcha.Text = "";
                        TxtEmail.Text = "";
                        TxtUserName.Text = "";
                        //lblStatus.Text = "Please check your email to get password!";
                        lblStatus.Text = message;
                    }
                }
                else
                {
                    const string script = "alert('Username and Email do not match!');";
                    ScriptManager.RegisterClientScriptBlock(UpdatePanel1,typeof(UpdatePanel),"wronguser",script,true);
                    TxtEmail.Focus();
                }
            }
            TxtCaptcha.Text = string.Empty;
        }

        protected void BtnBack_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("LogOn.aspx");
        }
    }
}
